package com.lbb.springboot.auto.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class ReplaceFile {
	public static void main(String[] args) {

		String inputFilePath = "F:\\kankan\\lbd.txt";
		String outputFilePath = "F:\\kankan\\lbdReplace.txt";
		replaceFile(inputFilePath, outputFilePath);
	}

	public static void replaceFile(String inputFilePath, String outputFilePath) {

		File file = null;

		BufferedReader br = null;

		String strLine = "";

		String strAllText = "";
		try {

			file = new File(inputFilePath);// 文件路径

			br = new BufferedReader(new FileReader(file));

			while ((strLine = br.readLine()) != null) {
				String[] projectName=new String[]{"lbd_server","appInterface","paymentGateway"};
				for (int i = 0; i < projectName.length; i++) {

					// java类 增
					strLine = strLine.replace(
							"Added : /code/"+projectName[i]+"/trunk/src/main/java",
							"/WEB-INF/classes");
					// java类 删
					strLine = strLine.replace(
							"Deleted : /code/"+projectName[i]+"/trunk/src/main/java",
							"/WEB-INF/classes");
					// java类 改
					strLine = strLine.replace(
							"Modified : /code/"+projectName[i]+"/trunk/src/main/java",
							"/WEB-INF/classes");

					// java替换 class
					strLine = strLine.replace(".java", ".class");

					//webapp 资源文件 增
					strLine = strLine.replace(
							"Added : /code/"+projectName[i]+"/trunk/src/main/webapp", "");

					
					//webapp 资源文件 删
					strLine = strLine.replace(
							"Deleted : /code/"+projectName[i]+"/trunk/src/main/webapp", "");
					
					strLine = strLine.replace(
							"Modified : /code/"+projectName[i]+"/trunk/src/main/webapp",
							"");
					
				}
				//webapp 资源文件 改
				strAllText=strAllText+strLine+"\r\n";
			
				outWirteFile(outputFilePath, strAllText);
			}

		} catch (FileNotFoundException e) {

			e.printStackTrace();

		} catch (IOException e) {

			e.printStackTrace();

		}

		System.out.println(strAllText);

	}

	public static void outWirteFile(String outFilePath, String text) {
		File file = new File(outFilePath);

		if (file.exists()) {
			file.delete();
		}

		if (!file.getParentFile().exists()) {
			file.getParentFile().mkdir();
		}

		try {
			file.createNewFile();
		} catch (IOException e) {
			e.printStackTrace();
		}

		BufferedWriter writer;
		try {
			writer = new BufferedWriter(
					new FileWriter(new File(file.getPath())));
			writer.write(text);
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
